
/*------------------------------------------------------*/
/* 				Stata Replication code for   			*/
/* 			Jacobs, Allen M. and Mark A. Kayser			*/
/*	Downward Mobility and Support for the Far Right:	*/
/*					Broad Evidence			 			*/
/*					  April 2025						*/
/*------------------------------------------------------*/
* data source: https://www.europeansocialsurvey.org/downloadwizard/

version 16.1


/*------------------------------------------*/
/*				Install Packages			*/
/*------------------------------------------*/


ssc install oesch, replace
ssc install tabout, replace
ssc install distinct, replace
ssc install sutex, replace
ssc install sutex2, replace
net install tabmiss.pkg, from(https://stats.oarc.ucla.edu/stat/stata/ado/analysis/) replace
ssc install drm, replace
ssc install blindschemes, replace all
set scheme plottig




/*------------------------------------------*/
/*					Load Data 				*/
/*------------------------------------------*/


pwd
* cd [enter path here]

use JacobsKayser_Replication_CPS_2025.dta




/*--------------------------------------------------------------------------*/
/*	              		Variable generation	& (re)coding					*/
/*--------------------------------------------------------------------------*/


gen essround_year = .
replace essround_year = 2002 if essround==1
replace essround_year = 2004 if essround==2
replace essround_year = 2006 if essround==3
replace essround_year = 2008 if essround==4
replace essround_year = 2010 if essround==5
replace essround_year = 2012 if essround==6
replace essround_year = 2014 if essround==7
replace essround_year = 2016 if essround==8
replace essround_year = 2018 if essround==9
replace essround_year = 2020 if essround==10
*tab essround essround_year




/*--- cntryessrnd ---*/	  
gen name2 = name
replace name2 = "ESS10merge" if name=="ESS10e02_2" | name=="ESS10SCe01_1"
encode cntry, gen(cntrynum)
*tab cntry cntrynum, nol
gen cntryessrnd = cntry+name2
*tab cntryessrnd
encode cntryessrnd, gen(cntryessrndnum)
*tab cntryessrndnum
*tab cntryessrndnum, nol 



/*----- Demographic vars -----*/
recode gndr (1=0)(2=1), gen(sex)
label var sex "female"
label var agea "age (years)"




/*--- education variables ---*/
* self (years)
label var eduyrs "education (years)"
* self (level)
egen edulvlseq = group(edulvlb), label
replace edulvlseq = . if edulvlseq ==26
label var edulvlseq "education level"
*tab edulvlseq, nolab

* father
egen edulvlfseq = group(edulvlfb), label
replace edulvlfseq = . if edulvlfseq ==26
label var edulvlfseq "father's edu level"
*tab edulvlfseq, nolab

*mother
egen edulvlmseq = group(edulvlmb), label
replace edulvlmseq = . if edulvlmseq ==26
label var edulvlmseq "mother's edu level"
*tab edulvlmseq, nolab




/*----- majority group -----*/
gen majgroup = .
replace majgroup = 1 if blgetmg == 2 // 2= not min group
replace majgroup = 0 if blgetmg == 1
replace majgroup = 1 if feethngr == 1 // feel part of same group as most people in cntry
replace majgroup = 0 if feethngr == 2
*table cntrynum essround, c(n blgetmg)
*table cntrynum essround, c(n feethngr)
*table cntrynum essround, c(n majgroup)





/*--------------------------------*/
/*------- Vote Variables ---------*/
/*--------------------------------*/


/*----------- FAR RIGHT PARTIES --------------*/


{
/*-----Vote for which party in last election-----*/
/*   Extended for Rounds 9 & 10 in 2023.  */
gen vpop = . // party voted for in last election
label var vpop "-- Voted for --" //voted for RWP party in last election"

*AT - Austria
replace vpop = 1 if prtvtat == 3 // FPÖ, essround 1 & 2
replace vpop = 0 if prtvtat <7 & prtvtat !=3 
replace vpop = 1 if prtvtaat == 3 | prtvtaat == 4 // FPÖ & BZÖ, essround 3
replace vpop = 0 if prtvtaat <9 & prtvtaat !=3 & prtvtaat !=4
replace vpop = 1 if prtvtbat == 3 | prtvtbat ==4 // FPÖ & BZÖ, essround 7 & 8
replace vpop = 0 if prtvtbat <11 & prtvtbat !=3 & prtvtbat !=4
replace vpop = 0 if prtvtcat < 10 & prtvtcat > 0 // FPÖ, essround 9 & 10
replace vpop = 1 if prtvtcat ==3


*BE - Belgium
replace vpop = 1 if prtvtbe == 8 | prtvtbe == 15 // Vlaams Block & Front National
replace vpop = 0 if prtvtbe <18 & prtvtbe !=8 & prtvtbe !=15
replace vpop = 1 if prtvtabe == 7 | prtvtabe == 11
replace vpop = 0 if prtvtabe <15 & prtvtabe !=7 & prtvtabe !=11
replace vpop = 1 if prtvtbbe == 7 | prtvtbbe == 11
replace vpop = 0 if prtvtbbe <15 & prtvtbbe !=7 & prtvtbbe !=11
replace vpop = 1 if prtvtcbe == 7 | prtvtcbe == 11
replace vpop = 0 if prtvtcbe <17 & prtvtcbe !=7 & prtvtcbe !=11
replace vpop = 0 if prtvtdbe <17 & prtvtdbe >0 // round 9, 10 missing
replace vpop = 1 if prtvtdbe == 7 | prtvtdbe == 11 // Vlaams Block, FN, essround 9


*CH - Switzerland  
replace vpop = 1 if prtvtch == 4 // Schweizerische Volkspartei (SVP).
replace vpop = 0 if prtvtch <17 & prtvtch != 4
replace vpop = 1 if prtvtach == 4
replace vpop = 0 if prtvtach <17 & prtvtach != 4
replace vpop = 1 if prtvtbch == 4
replace vpop = 0 if prtvtbch <14 & prtvtbch != 4
replace vpop = 1 if prtvtcch == 4
replace vpop = 0 if prtvtcch <14 & prtvtcch != 4
replace vpop = 1 if prtvtdch == 1
replace vpop = 0 if prtvtdch <17 & prtvtdch != 1
replace vpop = 1 if prtvtech == 1
replace vpop = 0 if prtvtech <19 & prtvtech != 1
replace vpop = 1 if prtvtfch == 1
replace vpop = 0 if prtvtfch <19 & prtvtfch != 1
replace vpop = 0 if prtvtgch <17 & prtvtgch >0 // wave 9
replace vpop = 1 if prtvtgch ==1 // SVP
replace vpop = 0 if prtvthch <21 & prtvtgch >0 // wave 10
replace vpop = 1 if prtvthch ==1 // SVP



*DE - Germany
replace vpop = 1 if prtvde2 == 6 // Republikaner.  Note: using prtvde2 to capture second ballot (zweite Stimme)
replace vpop = 0 if prtvde2 <8 & prtvde2 != 6
replace vpop = 1 if prtvade2 == 6 | prtvade2 == 7 // NDP
replace vpop = 0 if prtvade2 <9 & prtvade2 != 6 & prtvade2 !=7
replace vpop = 1 if prtvbde2 == 6 | prtvbde2 == 7
replace vpop = 0 if prtvbde2 <9 & prtvbde2 != 6 & prtvbde2 !=7
replace vpop = 1 if prtvcde2 == 6 | prtvcde2 == 7
replace vpop = 0 if prtvcde2 <9 & prtvcde2 != 6 & prtvcde2 !=7
replace vpop = 1 if prtvdde2 == 6 | prtvdde2 == 7
replace vpop = 0 if prtvdde2 <10 & prtvdde2 != 6 & prtvdde2 !=7
replace vpop = 1 if essround <9 & prtvede2 == 8 // NDP. essrounds 7 (2014),8 (2016). Round 8 asks about prev election (2013) when AfD not extremist; 97 AfD obs in round 7 and 58 AfD obs in round 8 coded as vpop=0.
replace vpop = 0 if essround <9 & prtvede2 <10 & prtvede2 !=8
replace vpop = 1 if essround ==9 & (prtvede2 == 6 | prtvede2 == 8) // AfD, NDP. essround 9 (2018). AfD in 2017 election is far right. 2015 change (Frauke Petry). 111 AfD obs in round 9 coded as vpop=1.
replace vpop = 0 if essround ==9 & prtvede2 <10 & prtvede2 != 6 & prtvede2 !=8
replace vpop = 0 if prtvfde2 <8 & prtvfde2 >0 // essround 10 (2020)
replace vpop = 1 if prtvfde2 ==6 // AfD



*DK - Denmark
replace vpop = 1 if prtvtdk == 6 | prtvtdk == 9 // Danish People's Party and Fremskridtspartiet
replace vpop = 0 if prtvtdk <12 & prtvtdk != 6 & prtvtdk != 9
replace vpop = 1 if prtvtadk == 6 | prtvtadk == 9
replace vpop = 0 if prtvtadk <12 & prtvtadk != 6 & prtvtadk != 9
replace vpop = 1 if prtvtbdk == 5 // no FP anymore
replace vpop = 0 if prtvtbdk <11 & prtvtbdk != 5
replace vpop = 1 if prtvtcdk == 5 // essrounds 6 & 7
replace vpop = 0 if prtvtcdk <11 & prtvtcdk != 5
replace vpop = 0 if prtvtddk <11 & prtvtddk>0 // essround 9
replace vpop = 1 if prtvtddk ==5 // Dansk Folkeparti




*FI - Finland
replace vpop = 1 if prtvtfi == 5  // True Finns
replace vpop = 0 if prtvtfi <15 & prtvtfi != 5
replace vpop = 1 if prtvtafi == 5  
replace vpop = 0 if prtvtafi <13 & prtvtafi != 5
replace vpop = 1 if prtvtbfi == 5  
replace vpop = 0 if prtvtbfi <20 & prtvtbfi != 5
replace vpop = 1 if prtvtcfi == 4  
replace vpop = 0 if prtvtcfi <19 & prtvtcfi != 4
replace vpop = 1 if prtvtdfi == 4  // essrounds 8 & 9
replace vpop = 0 if prtvtdfi <17 & prtvtdfi != 4
replace vpop = 0 if prtvtefi <23 & prtvtefi >0 // essround 10
replace vpop = 1 if prtvtefi == 5 // True Finns




*FR - France
replace vpop = 1 if prtvtfr == 3 | prtvtfr == 8 | prtvtfr == 11 // Front National, MPF (Mouvement pour la France), RPF (Rassemblement du Peuple Français is DeGauls party. RPF must mean Rassamblement pour la France.)
replace vpop = 0 if prtvtfr < 17 & prtvtfr != 3 & prtvtfr != 8 & prtvtfr != 11
replace vpop = 1 if prtvtafr == 3 | prtvtafr == 8 | prtvtafr == 11 
replace vpop = 0 if prtvtafr < 17 & prtvtafr != 3 & prtvtafr != 8 & prtvtafr != 11
replace vpop = 1 if prtvtbfr == 2 | prtvtbfr == 5 
replace vpop = 0 if prtvtbfr < 17 & prtvtbfr != 2 & prtvtbfr != 5
replace vpop = 1 if prtvtcfr == 2 | prtvtcfr == 8 
replace vpop = 0 if prtvtcfr < 15 & prtvtcfr != 2 & prtvtcfr != 8
replace vpop = 0 if prtvtdfr < 13 & prtvtdfr >0 // essround 9
replace vpop = 1 if prtvtdfr == 11 // FN
replace vpop = 0 if prtvtefr < 15 & prtvtefr >0 // essround 10
replace vpop = 1 if prtvtefr == 11 // FN



*GB - Great Britain
replace vpop = 1 if prtvtagb ==7 |prtvtagb == 8 // BNP & UKIP
replace vpop = 0 if prtvtagb < 11 & prtvtagb !=7 & prtvtgb !=8 // omit northern ireland parties
replace vpop = 1 if prtvtbgb == 7 // essrounds 7 & 8
replace vpop = 0 if prtvtbgb < 9 & prtvtbgb != 7
replace vpop = 0 if prtvtcgb < 20 & prtvtcgb >0 // essround 9
replace vpop = 1 if prtvtcgb == 7



*NL - Netherlands
replace vpop = 1 if prtvtnl == 4 // List Pim Fortuyn
replace vpop = 0 if prtvtnl < 12 & prtvtnl !=4
replace vpop = 1 if prtvtanl == 4 
replace vpop = 0 if prtvtanl < 13 & prtvtanl !=4
replace vpop = 1 if prtvtbnl == 4 
replace vpop = 0 if prtvtbnl < 12 & prtvtbnl !=4
replace vpop = 1 if prtvtcnl == 4 | prtvtcnl ==11 // + Group Geert Wilders (PVV)
replace vpop = 0 if prtvtcnl < 14 & prtvtcnl !=4 & prtvtcnl != 11
replace vpop = 1 if prtvtdnl == 3  
replace vpop = 0 if prtvtdnl < 13 & prtvtdnl !=3
replace vpop = 1 if prtvtenl == 3  
replace vpop = 0 if prtvtenl < 14 & prtvtenl !=3
replace vpop = 1 if prtvtfnl == 3 
replace vpop = 0 if prtvtfnl < 17 & prtvtfnl !=3
replace vpop = 0 if prtvtgnl <18 & prtvtgnl >0 // essround 9
replace vpop = 1 if prtvtgnl == 3 
replace vpop = 0 if prtvthnl <32 & prtvthnl >0 // essround 10
replace vpop = 1 if prtvthnl == 3 



*NO - Norway
replace vpop = 1 if prtvtno == 8 // Progress Party (FrP)
replace vpop = 0 if prtvtno<11 & prtvtno != 8
replace vpop = 1 if prtvtano == 8 
replace vpop = 0 if prtvtano<11 & prtvtano != 8
replace vpop = 1 if prtvtbno == 8 // essrounds 7,8, 9, 10
replace vpop = 0 if prtvtbno < 12 & prtvtbno != 8



*SE - Sweden
replace vpop = 1 if prtvtase == 10  // Sweden Democrats (Sverigedemokraterna). NB: ESS rounds 1-4 omitted because no RWPP.
replace vpop = 0 if prtvtase <12 & prtvtase != 10 
replace vpop = 1 if prtvtbse == 10 // essrounds 6, 7 8
replace vpop = 0 if prtvtbse <12 & prtvtbse != 10 
replace vpop = 0 if prtvtcse <11 & prtvtcse >0 // essround 9
replace vpop = 1 if prtvtcse == 9 // Sverigedemokraterna
replace vpop = 0 if prtvtdse <10 & prtvtdse >0 // essround 10
replace vpop = 1 if prtvtdse == 7


}







/*--------------------------*/
/*-----Close to Party-------*/
/*--------------------------*/

{
set more off
gen cpop = .
label var cpop "-- Close to --" //"feel close to RWP party"
* "Which party do you feel closer to?" (ESS wording)

*AT - Austria
replace cpop = 1 if prtclat == 3 // FPÖ, essround 1 & 2
replace cpop = 0 if prtclat <7 & prtvtat !=3 
replace cpop = 1 if prtclaat == 3 | prtclaat == 4 // FPÖ & BZÖ, essround 3
replace cpop = 0 if prtclaat <9 & prtclaat !=3 & prtclaat !=4
replace cpop = 1 if prtclcat == 3 | prtclcat ==4 // FPÖ & BZÖ, essround 7 & 8
replace cpop = 0 if prtclcat <11 & prtclcat !=3 & prtclcat !=4
replace cpop = 0 if prtcldat < 10 & prtcldat > 0 // FPÖ, essround 9 & 10
replace cpop = 1 if prtcldat ==3



*BE - Belgium
replace cpop = 1 if prtclbe == 8 | prtclbe == 15 // Vlaams Block, Vlaams Belang & Front National
replace cpop = 0 if prtclbe <17 & prtclbe !=8 & prtclbe !=15
replace cpop = 1 if prtclabe == 8 | prtclabe == 12
replace cpop = 0 if prtclabe <16 & prtclabe !=8 & prtclabe !=12
replace cpop = 1 if prtclbbe == 8 | prtclbbe == 12
replace cpop = 0 if prtclbbe <16 & prtclbbe !=8 & prtvtbbe !=12
replace cpop = 1 if prtclcbe == 7 | prtclcbe == 11
replace cpop = 0 if prtclcbe <17 & prtclcbe !=7 & prtclcbe !=11
replace cpop = 0 if prtcldbe <17 & prtcldbe >0 // round 9, 10 missing
replace cpop = 1 if prtcldbe == 7 | prtcldbe == 11 // Vlaams Block, FN, essround 9



*CH - Switzerland
*prtclch == 4 | prtclch == 11 | prtclch ==12 | prtclch==15 map to, respectively:Ldt(Ticino League), SD (Swiss Democrats), EDU-UDF (Fed Democratic Union...).  Schweizerische Volkspartei (SVP).
replace cpop = 0 if prtclch <17 & prtclch != 4 & prtclch != 11 & prtclch != 12 & prtclch != 15
replace cpop = 1 if prtclach == 4 | prtclach == 11 | prtclach ==12 | prtclach==15
replace cpop = 0 if prtclach <17 & prtclach != 4 & prtclach != 11 & prtclach != 12 & prtclach != 15
replace cpop = 1 if prtclbch == 4 | prtclbch == 10 | prtclbch ==11 | prtclbch==13
replace cpop = 0 if prtclbch <14 & prtclbch != 4 & prtclbch != 10 & prtclbch != 11 & prtclbch != 13
replace cpop = 1 if prtclcch == 4 | prtclcch == 10 | prtclcch ==11 | prtclcch==13
replace cpop = 0 if prtclcch <14 & prtclcch != 4 & prtclcch != 10 & prtclcch != 11 & prtclcch != 13
replace cpop = 1 if prtcldch == 1 | prtcldch == 9 | prtcldch ==10 | prtcldch ==15 // Movement of the citizens...
replace cpop = 0 if prtcldch <17 & prtcldch != 1 & prtcldch != 9 & prtcldch != 10 & prtcldch != 15
replace cpop = 1 if prtclech == 1 | prtclech == 9 | prtclech ==10 | prtclech == 12
replace cpop = 0 if prtclech <19 & prtclech != 1 & prtclech != 9 & prtclech != 10 & prtclech != 12
replace cpop = 1 if prtclfch == 1 | prtclfch == 9 | prtclfch ==10 | prtclech == 12
replace cpop = 0 if prtclfch <19 & prtclfch != 1 & prtclfch != 9 & prtclfch != 10 & prtclech != 12
replace cpop = 0 if prtclgch <17 & prtclgch >0 // wave 9
replace cpop = 1 if prtclgch ==1 // SVP
replace cpop = 0 if prtclhch <21 & prtclgch >0 // wave 10
replace cpop = 1 if prtclhch ==1 // SVP




*DE - Germany
replace cpop = 1 if prtclde == 6 // Republikaner.  Note: using prtvde2 to capture second ballot (zweite Stimme)
replace cpop = 0 if prtclde <8 & prtclde != 6
replace cpop = 1 if prtclade == 6 | prtclade == 7 // NDP
replace cpop = 0 if prtclade <9 & prtclade != 6 & prtclade !=7
replace cpop = 1 if prtclbde == 6 | prtclbde == 7
replace cpop = 0 if prtclbde <9 & prtclbde != 6 & prtclbde !=7
replace cpop = 1 if prtclcde == 6 | prtclcde == 7
replace cpop = 0 if prtclcde <9 & prtclcde != 6 & prtclcde !=7
replace cpop = 1 if prtcldde == 6 | prtcldde == 7
replace cpop = 0 if prtcldde <10 & prtcldde != 6 & prtcldde !=7
replace cpop = 1 if essround <9 & prtclede == 8 // NDP. essrounds 7 (2014),8 (2016). Round 8 asks about prev election (2013) when AfD not extreme
replace cpop = 0 if essround <9 & prtclede <10 & prtclede !=8
replace cpop = 1 if essround ==9 & (prtclede == 6 | prtclede == 8) // AfD, NDP. essround 9 (2018). AfD in 2017 election as far right. 2015 change
replace cpop = 0 if essround ==9 & prtclede <10 & prtclede != 6 & prtclede !=8
replace cpop = 0 if prtclfde <8 & prtclfde >0 // essround 10, n. obs jumps radically in this round.
replace cpop = 1 if prtclfde ==6 // AfD




*DK - Denmark
replace cpop = 1 if prtcldk == 6  // Danish People's Party
replace cpop = 0 if prtcldk <12 & prtcldk != 6
replace cpop = 1 if prtcladk == 6 
replace cpop = 0 if prtcladk <12 & prtcladk != 6
replace cpop = 1 if prtclbdk == 5 
replace cpop = 0 if prtclbdk <11 & prtclbdk != 5
replace cpop = 1 if prtclcdk == 5 
replace cpop = 0 if prtclcdk <11 & prtclcdk != 5
replace cpop = 0 if prtclddk <11 & prtclddk>0 // essround 9
replace cpop = 1 if prtclddk ==5 // Dansk Folkeparti




*FI - Finland
replace cpop = 1 if prtclfi == 5  // True Finns.  (but note left-wing econ policy)
replace cpop = 0 if prtclfi <15 & prtclfi != 5
replace cpop = 1 if prtvtafi == 5  
replace cpop = 0 if prtclafi <13 & prtclafi != 5
replace cpop = 1 if prtclbfi == 5  
replace cpop = 0 if prtclbfi <20 & prtclbfi != 5
replace cpop = 1 if prtclcfi == 4  
replace cpop = 0 if prtclcfi <19 & prtclcfi != 4
replace cpop = 1 if prtcldfi == 4  // essrounds 8 & 9
replace cpop = 0 if prtcldfi <17 & prtcldfi != 4
replace cpop = 0 if prtclefi <19 & prtclefi >0 // essround 10
replace cpop = 1 if prtclefi == 4 // True Finns. NB: party nums diff than with vpop.




*FR - France
replace cpop = 1 if prtclfr == 3 | prtclfr == 7 | prtclfr == 8 // Front National, MNR, MPF
replace cpop = 0 if prtclfr < 17 & prtclfr != 3 & prtclfr != 7 & prtclfr != 8
replace cpop = 1 if prtclafr == 2 | prtclafr == 6 | prtclafr == 7 
replace cpop = 0 if prtclafr < 16 & prtclafr != 2 & prtclafr != 6 & prtclafr != 7
replace cpop = 1 if prtclbfr == 2 | prtclbfr == 6 
replace cpop = 0 if prtclbfr < 16 & prtclbfr != 2 & prtclbfr != 6 
replace cpop = 1 if prtclcfr == 1 // essround 5
replace cpop = 0 if prtclcfr < 16 & prtclcfr != 1 
replace cpop = 0 if prtcldfr < 17 & prtcldfr >0 // essround 6 & 7
replace cpop = 1 if prtcldfr == 2 // FN
replace cpop = 0 if prtclefr < 17 & prtclefr >0 // essround 8
replace cpop = 1 if prtclefr == 2 // FN
replace cpop = 0 if prtclffr < 13 & prtclffr >0 // essrounds 9 & 10
replace cpop = 1 if prtclffr == 11




*GB - Great Britain -- nb. BNP is extreme right wing but not populist.
replace cpop = 1 if prtclagb==8   // UKIP.  NB: ESS rounds 3, 7 & 8 only; others have no RRWPs.
replace cpop = 0 if prtclagb <23 & prtclagb !=8
replace cpop = 1 if prtclbgb == 7 
replace cpop = 0 if prtclbgb <19 & prtclbgb !=7
replace cpop = 0 if prtclcgb < 20 & prtclcgb >0 // essround 9
replace cpop = 1 if prtclcgb == 7



*NL - Netherlands
replace cpop = 1 if prtclnl == 4 // List Pim Fortuyn
replace cpop = 0 if prtclnl < 12 & prtclnl !=4
replace cpop = 1 if prtclanl == 4 | prtclanl == 12 // + Group Geert Wilders (PVV)
replace cpop = 0 if prtclanl < 16 & prtclanl !=4 & prtclanl != 12
replace cpop = 1 if prtclbnl == 4 | prtclbnl == 11 // 
replace cpop = 0 if prtclbnl < 14 & prtclbnl !=4 & prtclbnl != 11
replace cpop = 1 if prtclcnl == 3 // 
replace cpop = 0 if prtclcnl < 13 & prtclcnl !=3
replace cpop = 1 if prtcldnl == 3 // 
replace cpop = 0 if prtcldnl < 14 & prtcldnl !=3
replace cpop = 1 if prtclenl == 3 // essrounds 7 & 8
replace cpop = 0 if prtclenl < 17 & prtclenl !=3
replace cpop = 1 if prtclfnl == 3  // essround 9
replace cpop = 0 if prtclfnl < 17 & prtclfnl !=3
replace cpop = 0 if prtclgnl <20 & prtclgnl >0 // essround 10
replace cpop = 1 if prtclgnl == 3 



*NO - Norway
replace cpop = 1 if prtclno == 8 // Progress Party (FrP)
replace cpop = 0 if prtclno<11 & prtclno != 8
replace cpop = 1 if prtclano == 8 
replace cpop = 0 if prtclano<11 & prtclano != 8
replace cpop = 1 if prtclbno == 8 // essrounds 7, 8, 9, 10
replace cpop = 0 if prtclbno<12 & prtclbno != 8



*SE - Sweden
replace cpop = 1 if prtclase == 10  // Sweden Democrats (Sverigedemokraterna). NB: ESS rounds 1-4 omitted because no RWPP.
replace cpop = 0 if prtclase <12 & prtclase != 10 
replace cpop = 1 if prtclbse == 10
replace cpop = 0 if prtclbse <12 & prtclbse != 10 
replace cpop = 0 if prtclcse <11 & prtclcse >0 // essround 9
replace cpop = 1 if prtclcse == 9 // Sverigedemokraterna
replace cpop = 0 if prtcldse <10 & prtcldse >0 // essround 10
replace cpop = 1 if prtcldse == 7

}



/*------------------------------------------*/
/*	Intergenerational Occupational Mobility	*/
/*------------------------------------------*/

/*--- does father or mother higher occ status? ---*/

gen occm_higher = .
replace occm_higher = 0 if occm14 >= occf14 & occm14 != . & occf14 != . // lower score means higher status
replace occm_higher = 1 if occm14 < occf14 & occm14 != . & occf14 != .  

replace occm_higher = 0 if occm14a >= occf14a & occm14a != . & occf14a != . // lower score means higher status
replace occm_higher = 1 if occm14a < occf14a & occm14a != . & occf14a != .  

replace occm_higher = 0 if occm14b >= occf14b & occm14b != . & occf14b != . // lower score means higher status
replace occm_higher = 1 if occm14b < occf14b & occm14b != . & occf14b != .  
*br occm_higher occm14 occf14 occm14a occf14a occm14b occf14b

label var occm_higher "mother occ status higher than father"




/*------- Father's Occupation -------*/

* Intergen change father (self minus father)
* recode parent occ into something like Oesch4, ie Oesch5 (see below) with small business owners promoted to lower-grade service class

recode occf14 (1=1) (2=2) (3=2) (4=1) (5=3) (6=3) (7=4) (8=2) (.a=.) (.b=.) (.c=.) (.d=.), gen(occfoesch1)
recode occf14a (1=1) (2=2) (3=2) (4=1) (5=3) (6=3) (7=4) (8=2) (.a=.) (.b=.) (.c=.) (.d=.), gen(occfoescha)
recode occf14b (1=1) (2=1) (3=2) (4=2) (5=2) (6=3) (7=3) (8=4) (9=4) , gen(occfoeschb) 

* combine for all waves (occfoesch4)
gen occfoesch4 =.
replace occfoesch4= occfoesch1 if occf14!=.
replace occfoesch4= occfoescha if occf14a !=.
replace occfoesch4= occfoeschb if occf14b !=.
replace occfoesch4 = . if occfoeschb==.a | occfoeschb ==.b | occfoeschb ==.c | occfoeschb ==.d



/*------- Mother's Occupation -------*/
* see Father's Occ section above for comments

recode occm14 (1=1) (2=2) (3=2) (4=1) (5=3) (6=3) (7=4) (8=2) (.a=.) (.b=.) (.c=.) (.d=.), gen(occmoesch1)
recode occm14a (1=1) (2=2) (3=2) (4=1) (5=3) (6=3) (7=4) (8=2) (.a=.) (.b=.) (.c=.) (.d=.), gen(occmoescha)
recode occm14b (1=1) (2=1) (3=2) (4=2) (5=2) (6=3) (7=3) (8=4) (9=4) , gen(occmoeschb) 

* combine for all waves
gen occmoesch4 =.
replace occmoesch4= occmoesch1 if occm14!=.
replace occmoesch4= occmoescha if occm14a !=.
replace occmoesch4= occmoeschb if occm14b !=.
replace occmoesch4 = . if occmoeschb==.a | occmoeschb ==.b | occmoeschb ==.c | occmoeschb ==.d



/*--- select most prestigious occ status of mother and father ---*/

gen occpoesch4 = . // p for parent
replace occpoesch4 = occmoesch4 if occmoesch4 < occfoesch4 // includes missing occfoesch4 (= pos infinity)
replace occpoesch4 = occfoesch4 if occmoesch4 >= occfoesch4  // lower val is higher prestige
label def occpoesch4 1 "highest" 2 "2nd" 3 "3rd" 4 "lowest"
lab val occpoesch4 occpoesch4 
lab var occpoesch4 "parent's occ. status"
tab occpoesch4, gen(occparent)




/*---- Respondent occupation ----*/

* build one occupational status variable based on Oesch 5-category scale (Oesch 2006).
* oesch8 and oesch16 less appropriate for social mobility analysis
* iscoco (ESS 1-5)
* isco08 (ESS 6-10)

iskooesch i88, emplrel(emplrel) emplno(emplno) isko(iscoco) five  
iscooesch i08, emplrel(emplrel) emplno(emplno) isco(isco08) five 

* Combine into one Oesch5 variable
set more off
replace oesch5_i88 = . if essround>5 
gen oesch5 =.
replace oesch5 = oesch5_i88 if essround<6
replace oesch5 = oesch5_i08 if essround>5 
label var oesch5 "occupational Status"
drop oesch5_i08 oesch5_i88

* Reduce to four categories to match parent occ scale above
recode oesch5 (1=1)(2=2)(3=2)(4=3)(5=4), gen(oesch4)
label var oesch4 "occupational status"
label def oesch4 1 "highest" 2 "2nd" 3 "3rd" 4 "lowest"
lab val oesch4 oesch4 
tab oesch4, gen(occresp) // respondent occ dummies




/*-------- intergenerational change (intgench) ----------*/

/*--- downward occ status mobility --- */	
* for downward social mobility, we subtract parent from respondent so pos value means downward mobility.
* we'll reverse this scale for upward mobility below with a new variable, so we have a choice for interpretation
 
gen intgench = oesch4 - occpoesch4
label var intgench "downward occupation mobility"
lab def intgench -3 "up3" -2 "up2" -1 "up1" 0 "0" 1 "down1" 2 "down2" 3 "down3", modify
lab val intgench intgench

/*---- occu change dummies ----*/
gen up3 = .
replace up3 = 1 if intgench == -3
replace up3 = 0 if intgench < 4 & intgench != -3

gen up2 = .
replace up2 = 1 if intgench == -2
replace up2 = 0 if intgench < 4 & intgench != -2

gen up1 = .
replace up1 = 1 if intgench == -1
replace up1 = 0 if intgench < 4 & intgench != -1

gen updown0 = .
replace updown0 = 1 if intgench == 0
replace updown0 = 0 if intgench < 4 & intgench !=0

gen down1 = .
replace down1 = 1 if intgench == 1
replace down1 = 0 if intgench < 4 & intgench !=1

gen down2 = .
replace down2 = 1 if intgench == 2
replace down2 = 0 if intgench < 4 & intgench !=2

gen down3 = .
replace down3 = 1 if intgench == 3
replace down3 = 0 if intgench < 4 & intgench !=3


/*---- upward mobility ---*/
gen intgenchrev = intgench*(-1)
lab var intgenchrev "upward occupational mobility"



di "finished making variables"
exit





/*------------------------------------------*/
/*		Tables and Figures in Paper			*/
/*------------------------------------------*/

/*--- Table 1: Lists far right parties; not from data analysis ---*/



/*--- Table 2: Share of Votes for Far Right by Mobility ---*/
qui: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if agea > 30 /// 
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) // Model 1 from main LPM table	
eststo clear
eststo: estpost tab intgench vpop if e(sample)
*esttab, cell("b pct(fmt(0))") unstack noobs tex
esttab, cell(rowpct(fmt(2)) b(fmt(g) par keep(Total))) collabels(none) nonumber nomtitle unstack noobs //tex



/*--- Table 3: Main LPM table; VPOP and CPOP; Country-essround FE ---*/
set more off
eststo clear
qui eststo: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if agea > 30 /// 
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) 
qui eststo: reg cpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if agea > 30 ///
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) 
esttab, n b(3) se(3) r2 ar2 replace wide label keep(up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex) //tex
distinct cntryessrndnum if e(sample) // number of clusters



/*--- Figure 1: LPM AME by Mobility ---*/
qui: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if agea > 30 /// 
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) 
coefplot, xline(0) title("Avg. Marginal Effect by Mobility")  keep(up3 up2 up1 down1 down2 down3) //saving(mob_dummies)
gr export f_ess_vpop_mobdummy_coefs.pdf, replace






	
/*---- Figure 2 top panel: LPM country-by-country -----*/
* appendix table A13
set more off
eststo clear
qui eststo ALL: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1, r 
qui eststo AT: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "AT", r
qui eststo BE: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "BE", r
qui eststo CH: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "CH", r
qui eststo DE: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "DE", r
qui eststo DK: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "DK", r
qui eststo FI: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "FI", r
qui eststo FR: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "FR", r
qui eststo GB: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "GB", r
qui eststo NL: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "NL", r
qui eststo NO: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "NO", r
qui eststo SE: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "SE", r

coefplot ALL AT BE CH DE DK FI FR GB NL NO SE, xline(0) keep(intgenchrev) ///
	title("Avg. Marginal Effect by Country") ylabel("") legend(position(9) cols(1) ring(2)) ///
	bycoefs saving(cbyc)

	
	
/*---- Figure 2 bottom panel: LPM round-by-round ---*/
* appendix table A14
set more off
eststo clear
qui eststo ALL: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1, r 
qui eststo R1: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & essround == 1, r
qui eststo R2: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & essround == 2, r
qui eststo R3: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & essround == 3, r
qui eststo R4: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & essround == 4, r
qui eststo R5: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & essround == 5, r
qui eststo R6: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & essround == 6, r
qui eststo R7: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & essround == 7, r
qui eststo R8: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & essround == 8, r
qui eststo R9: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & essround == 9, r
qui eststo R10: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & essround == 10, r

coefplot ALL R1 R2 R3 R4 R5 R6 R7 R8 R9 R10, xline(0) keep(intgenchrev) ///
	title("Avg. Marginal Effect by ESS Round (2002 - 2020)") ylabel("") legend(position(9) cols(1) ring(2)) ///
	bycoefs saving(rbyr)

* combine panels
gr combine  cbyc.gph rbyr.gph, col(1) iscale(.8) saving(f_duo_ess_vpop_subset_coefs)	
gr export f_duo_ess_vpop_subset_coefs.pdf, replace






/*--- Table 4: Mobility by repondent occupational status category ---*/
* note: e(sample) from M1, T3 that uses occpoesch4
* xtab intgench oesch4 if >30
qui: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if agea > 30 /// 
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) // Model 1 from main LPM table 	
eststo clear
eststo: estpost tab intgench oesch4 if e(sample)
esttab, cell(colpct(fmt(2)) b(fmt(g) par keep(Total))) collabels(none) nonumber nomtitle unstack noobs //tex





/*--- Figure 3: Theoretical model (DAG) not derived from data ---*/









/*------ Table 5: DRM Main Table. VPOP DV, logit link, Fixed Effects ------*/

eststo clear
set more off
eststo: drm vpop occpoesch4 oesch4 up3 up2 up1 down1 down2 down3 agea eduyrs sex i.cntrynum if agea > 30 & majgroup ==1 & brncntr ==1, link(logit) 

esttab, n se(2) b(3) bic(0) wide replace label //tex 





/*--- Figure 4: exponentiated coeff plot; factor change in the odds ---*/

coefplot, eform xline(1) title("Vote, factor change in odds") keep(up3 up2 up1 down1 down2 down3) nolab xtitle()
graph export f_drm_vpop_eform.pdf, replace






/*--- Figure 5: DRM coeff plots for four attitudinal outcomes, linear link ---*/
* see appendix table A20 for full DRM.
eststo clear
set more off
*trust in politicians
drm trstplt occpoesch4 oesch4 up3 up2 up1 down1 down2 down3 agea eduyrs sex i.cntrynum if agea > 30 ///
	& majgroup ==1 & brncntr ==1 & vpop !=., link(linear) 
qui: coefplot, xline(0) title("Trust in politicians") keep(up3 up2 up1 down1 down2 down3) nolab nodraw saving(drmtrustpol)
	
* sat with democ
drm stfdem occpoesch4 oesch4 up3 up2 up1 down1 down2 down3 agea eduyrs sex i.cntrynum if  agea > 30 /// 
	& majgroup ==1 & brncntr ==1 & vpop !=., link(linear) ownc([p]_cons=1) // tech(bhhh)
qui: coefplot, xline(0) title("Satisfaction with democ.") keep(up3 up2 up1 down1 down2 down3) nolab nodraw saving(drmsatdem)

* immigrants enrich culture
drm imueclt occpoesch4 oesch4 up3 up2 up1 down1 down2 down3 agea eduyrs sex i.cntrynum if agea > 30 /// 
	& majgroup ==1 & brncntr ==1 & vpop !=., link(linear) 
qui: coefplot, xline(0) title("Immigrants culture") keep(up3 up2 up1 down1 down2 down3) nolab nodraw saving(drmimmcult)
	
* immigrants bad or good for econ?
drm imbgeco occpoesch4 oesch4 up3 up2 up1 down1 down2 down3 agea eduyrs sex i.cntrynum if agea > 30 /// 
	& majgroup ==1 & brncntr ==1 & vpop !=., link(linear) 	
qui: coefplot, xline(0) title("Immigrants economy") keep(up3 up2 up1 down1 down2 down3) nolab nodraw saving(drmimmecon)
	
* combine 
gr combine drmtrustpol.gph drmsatdem.gph drmimmcult.gph drmimmecon.gph, col(2)

graph export f_quad_drm_attitude.pdf, replace







/*------------------------------------------------------------------*/
/*					Tables and Figures in the 						*/
/*						Online Appendix								*/
/*------------------------------------------------------------------*/




/*-------------- Table A1: Cross-tab for sample: country & ess-round ----------------*/
* overview of which countries participate in which rounds, AFTER listwise deletion:
qui: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if agea > 30 /// 
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) // Model 1 from main LPM table [T1]
tabout cntrynum essround using tab_freq_cntry_essround.tex if e(sample), f(0 )style(tex) replace





/*------------ Table A2. Summary stats table for analytic samples ---------*/
qui: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if agea > 30 /// 
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum)
tab cntry if e(sample), gen(cty)
tab essround if e(sample), gen(round)	
sutex2 vpop up3 up2 up1 updown0 down1 down2 down3 occresp* occparent* occm_higher agea sex cty* round* if e(sample), minmax varlab dig(2) 
drop cty* round*




/*--------------- Table A3: Listwise deletion in main model --------*/
tabmiss up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex if vpop !=. & agea>30 & majgroup==1 & brncntr ==1




/*--- Table A4: cross-tab parent's occ & occ change if resp > 30 years old ---*/
* xtab intgench occpoesch4 if >30
qui: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if agea > 30 /// 
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) // Model 1 from main LPM table	
eststo clear
qui eststo: estpost tab intgench occpoesch4 if e(sample)
*esttab, cell("b pct(fmt(0))") unstack noobs tex
esttab, cell(colpct(fmt(2)) b(fmt(g) par keep(Total))) collabels(none) nonumber nomtitle unstack noobs //tex





/*---  Table A5: cross-tab parent's occ & occ change if resp >35 years old ---*/
qui: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if agea > 35 /// 
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) // Model 1 from main LPM table 	
eststo clear
eststo: estpost tab intgench occpoesch4 if e(sample)
*esttab, cell("b pct(fmt(0))") unstack noobs tex
esttab, cell(colpct(fmt(2)) b(fmt(g) par keep(Total))) collabels(none) nonumber nomtitle unstack noobs //tex




/*--- Table A6: cross-tab respondent occ and occ change if resp >35 years old ---*/
* note: Table 2 in main paper shows version of this table with respondents older than 30 years.
quietly: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if agea > 35 /// 
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) // Model 1 from main LPM table	
eststo clear
qui eststo: estpost tab intgench oesch4 if e(sample)
*esttab, cell("b pct(fmt(0))") unstack noobs tex
esttab, cell(colpct(fmt(2)) b(fmt(g) par keep(Total))) collabels(none) nonumber nomtitle unstack noobs //tex




/*--- Table 2: cross-tab respondent occ and occ change if resp >30 years old ---*/
* This table is included in the main paper
qui: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if agea > 30 /// 
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) // Model 1 from main LPM table	
eststo clear
qui eststo: estpost tab intgench vpop if e(sample)
*esttab, cell("b pct(fmt(0))") unstack noobs tex
esttab, cell(rowpct(fmt(2)) b(fmt(g) par keep(Total))) collabels(none) nonumber nomtitle unstack noobs //tex





/*--- Table A7: coding of far-right parties. hand coded. not derived from data. ---*/






/*--- Table A8:     ---*/




/*--- Table A8: LPM with country FE (not country-essround fe)  ---*/
set more off
eststo clear
qui eststo: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntrynum if agea > 30 & majgroup ==1 & brncntr ==1, r 
qui eststo: reg cpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntrynum if agea > 30 & majgroup ==1 & brncntr ==1, r 
esttab, n b(3) se(3) r2 replace wide label keep(up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex) //tex




/*--- Table A9: LPM country-essround FE (i.e, survey FE) OMMITTING EDU YEARS ---*/
set more off
eststo clear
qui eststo: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea sex i.cntryessrndnum if agea > 30 /// 
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) 
qui eststo: reg cpop up3 up2 up1 down1 down2 down3 occpoesch4 agea sex i.cntryessrndnum if agea > 30 ///
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) 
esttab, n b(3) se(3) r2 wide label replace keep(up3 up2 up1 down1 down2 down3 occpoesch4 agea sex) //tex




/*--- Table A10: LPM country-essround FE with EDUCATION LEVEL, not YEARS oF EDU  ---*/
*ESS rounds 1-4 drop out because of missing edu level obs. 
set more off
eststo clear
qui eststo: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea edulvlseq sex i.cntryessrndnum if agea > 30 /// 
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum)  
qui eststo: reg cpop up3 up2 up1 down1 down2 down3 occpoesch4 agea edulvlseq sex i.cntryessrndnum if agea > 30 ///
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) 
esttab, n b(3) se(3) r2 wide label replace keep(up3 up2 up1 down1 down2 down3 occpoesch4 agea edulvlseq sex) //tex



	
/*--- Table A11: LPM country-essround FE WITH Father & Mother EDUCATION levels ---*/
set more off
eststo clear
*eststo: reg vpop intgench occpoesch4 agea eduyrs sex i.cntryessrndnum if agea > 30 & majgroup ==1 & brncntr ==1 
qui eststo: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs edulvlfseq edulvlmseq sex i.cntryessrndnum if agea > 30 & majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) 

qui eststo: reg cpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs edulvlfseq edulvlmseq sex i.cntryessrndnum if agea > 30 & majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) 

esttab, n b(3) se(3) r2 wide label replace keep(up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs edulvlfseq edulvlmseq sex) //tex





/*---------- Table A12: DRM including respondent's and both parents' edu level -----------*/

eststo clear
set more off
* edu level seq categories. edulvlfb and edulvlmb recoded so cats have sequential vals on 25 pt scale.
* ESS rounds 1-4 drop out due to missing edu obs. 25 pt scale question introduced in round 5. 
eststo: drm vpop occpoesch4 oesch4 up3 up2 up1 down1 down2 down3 agea edulvlseq edulvlfseq edulvlmseq sex i.cntrynum if agea > 30 & majgroup ==1 & brncntr ==1, link(logit) 
eststo: drm cpop occpoesch4 oesch4 up3 up2 up1 down1 down2 down3 agea edulvlseq edulvlfseq edulvlmseq sex i.cntrynum if agea > 30 & majgroup ==1 & brncntr ==1, link(logit)
esttab, n se(3) b(3) bic(0) wide replace label //tex 





	
/*---- Table A13: LPM country-by-country -----*/
set more off
eststo clear
qui eststo ALL: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1, r 
qui eststo AT: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "AT", r
qui eststo BE: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "BE", r
qui eststo CH: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "CH", r
qui eststo DE: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "DE", r
qui eststo DK: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "DK", r
qui eststo FI: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "FI", r
qui eststo FR: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "FR", r
qui eststo GB: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "GB", r
qui eststo NL: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "NL", r
qui eststo NO: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "NO", r
qui eststo SE: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & cntry == "SE", r
* use for table:
esttab, n b(3) se(2) r2 label replace //tex



	
	
/*---- Table A14: LPM round-by-round ---*/
set more off
eststo clear
qui eststo ALL: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1, r 
qui eststo R1: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & essround == 1, r
qui eststo R2: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & essround == 2, r
qui eststo R3: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & essround == 3, r
qui eststo R4: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & essround == 4, r
qui eststo R5: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & essround == 5, r
qui eststo R6: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & essround == 6, r
qui eststo R7: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & essround == 7, r
qui eststo R8: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & essround == 8, r
qui eststo R9: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & essround == 9, r
qui eststo R10: reg vpop intgenchrev occpoesch4 agea eduyrs sex if agea > 30 & majgroup ==1 & brncntr ==1 & essround == 10, r

esttab, n b(3) se(2) r2 label replace //tex






/*--- Table A15: DRM with vote DV, rounds 1-5 and 6-10 ---*/

eststo clear
set more off
* rounds 1-5
eststo: drm vpop occpoesch4 oesch4 up3 up2 up1 down1 down2 down3 agea eduyrs sex i.cntrynum if agea > 30 & majgroup ==1 & brncntr ==1 & essround <=5, link(logit) // mobility dummies and fe
* rounds 6-10
eststo: drm vpop occpoesch4 oesch4 up3 up2 up1 down1 down2 down3 agea eduyrs sex i.cntrynum if agea > 30 & majgroup ==1 & brncntr ==1 & essround >5, link(logit) // mobility dummies and fe

esttab, n se(2) b(3) bic(0) wide replace label collabels(none) mtitle("Rounds 1-5" "Rounds 6-10") //tex 





/*--- Table A16: DRM with "Close To" DV, rounds 1-5 and rounds 6-10 ---*/

eststo clear
set more off
*all:
eststo: drm cpop occpoesch4 oesch4 up3 up2 up1 down1 down2 down3 agea eduyrs sex i.cntrynum if agea > 30 & majgroup ==1 & brncntr ==1, link(logit) // mobility dummies and fe
*rounds 1-5:
eststo: drm cpop occpoesch4 oesch4 up3 up2 up1 down1 down2 down3 agea eduyrs sex i.cntrynum if agea > 30 & majgroup ==1 & brncntr ==1 & essround <=5, link(logit) // mobility dummies and fe
*rounds 6-10:
eststo: drm cpop occpoesch4 oesch4 up3 up2 up1 down1 down2 down3 agea eduyrs sex i.cntrynum if agea > 30 & majgroup ==1 & brncntr ==1 & essround >5, link(logit) // mobility dummies and fe

esttab, n se(2) b(3) bic(0) wide replace label collabels(none) mtitle("All" "Rounds 1-5" "Rounds 6-10") //tex 





													
/*------ Table 17: LPM, three age cutoffs, vpop and cpop --------*/
	
*country-essround FE
set more off
eststo clear
eststo: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if agea > 25 /// 
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) 	
eststo: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if agea > 30 /// 
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) 
eststo: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if agea > 35 /// 
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) 	
	
eststo: reg cpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if agea > 25 ///
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) 	
eststo: reg cpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if agea > 30 ///
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum)	
eststo: reg cpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if agea > 35 ///
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum)
	
esttab, n b(3) se(2) r2 label replace keep(up3 up2 up1 down1 down2 down3 occpoesch4 eduyrs agea sex _cons) //tex

	
	

/*---- Table 18: LPM, results by sex; vpop and cpop ----*/	
set more off
eststo clear
eststo: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if agea > 30 /// 
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) 
eststo: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs i.cntryessrndnum if agea > 30 /// 
	& majgroup ==1 & brncntr ==1 & sex==0, cluster(cntryessrndnum)
eststo: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs i.cntryessrndnum if agea > 30 /// 
	& majgroup ==1 & brncntr ==1 & sex==1, cluster(cntryessrndnum)	
	
eststo: reg cpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if agea > 30 ///
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) 
eststo: reg cpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs i.cntryessrndnum if agea > 30 ///
	& majgroup ==1 & brncntr ==1 & sex==0, cluster(cntryessrndnum)
eststo: reg cpop up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs i.cntryessrndnum if agea > 30 ///
	& majgroup ==1 & brncntr ==1 & sex==1, cluster(cntryessrndnum)	
	
esttab, n b(3) se(3) r2 ar2 replace label keep(up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex _cons) //tex	
	
	

	


* Table A19: LPM with 4 attitudinal dvs
* set sample to match main vpop model
qui: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea sex i.cntryessrndnum if agea > 30 /// 
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) 
gen esmpl = e(sample)
set more off
eststo clear
eststo: reg trstplt up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if esmpl==1, cluster(cntryessrndnum) 
eststo: reg stfdem up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if esmpl==1, cluster(cntryessrndnum)  
eststo: reg imueclt up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if esmpl==1, cluster(cntryessrndnum)
eststo: reg imbgeco up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if esmpl==1, cluster(cntryessrndnum)
  
esttab, n se(2) b(3) r2 keep(up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex _cons) replace label //tex 
drop esmpl






/*---- Figure A1: coefficient plots for attitudinal DVs ----*/
* coefplots
qui: reg vpop up3 up2 up1 down1 down2 down3 occpoesch4 agea sex i.cntryessrndnum if agea > 30 /// 
	& majgroup ==1 & brncntr ==1, cluster(cntryessrndnum) 
gen esmpl = e(sample)
qui: reg trstplt up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if esmpl==1, cluster(cntryessrndnum) 
coefplot, xline(0) title("Trust pol.") xtitle((a)) keep (up3 up2 up1 down1 down2 down3) saving(trustpol) // f_ESS_politicians.pdf
qui: reg stfdem up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if esmpl==1, cluster(cntryessrndnum) 
coefplot, xline(0) title("Sat. dem.") xtitle((b)) keep (up3 up2 up1 down1 down2 down3) saving(satdem) // f_ESS_democracy.pdf 
qui: reg imueclt up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if esmpl==1, cluster(cntryessrndnum)  
coefplot, xline(0) title("Imm. Culture") xtitle((c)) keep (up3 up2 up1 down1 down2 down3) saving(immcult) // f_ESS_imm_cult.pdf
qui: reg imbgeco up3 up2 up1 down1 down2 down3 occpoesch4 agea eduyrs sex i.cntryessrndnum if esmpl==1, cluster(cntryessrndnum)  
coefplot, xline(0) title("Imm. Econ.") xtitle((c)) keep (up3 up2 up1 down1 down2 down3) saving(immecon) // f_ESS_imm_econ.pdf

gr combine trustpol.gph satdem.gph immcult.gph immecon.gph, col(2) iscale(.6)
gr export f_quad_attitudes.pdf, replace

drop esmpl

	
	



/*--------- Table A20: DRM for attitudinal DVs, vpop, linear link -------*/
eststo clear
set more off
*tust in politicians
eststo: drm trstplt occpoesch4 oesch4 up3 up2 up1 down1 down2 down3 agea eduyrs sex i.cntrynum if agea > 30 ///
	& majgroup ==1 & brncntr ==1 & vpop !=., link(linear) 
	
* sat with democ
eststo: drm stfdem occpoesch4 oesch4 up3 up2 up1 down1 down2 down3 agea eduyrs sex i.cntrynum if  agea > 30 /// 
	& majgroup ==1 & brncntr ==1 & vpop !=., link(linear) ownc([p]_cons=1) // tech(bhhh)

* immigrants enrich culture
eststo: drm imueclt occpoesch4 oesch4 up3 up2 up1 down1 down2 down3 agea eduyrs sex i.cntrynum if agea > 30 /// 
	& majgroup ==1 & brncntr ==1 & vpop !=., link(linear) 
	
* immigrants bad or good for econ?
eststo: drm imbgeco occpoesch4 oesch4 up3 up2 up1 down1 down2 down3 agea eduyrs sex i.cntrynum if agea > 30 /// 
	& majgroup ==1 & brncntr ==1 & vpop !=., link(linear) 	
	
esttab, n se(2) b(3) bic(0) wide label replace //tex






